<?
	   layout("/inc/win_layout.html",{title:sysTitle}){
?>
<link rel="stylesheet" href="static/codemirror/lib/codemirror.css" type="text/css"></link>
<div class="panel" style="height: 580px; overflow: auto;">
	<div class="row" style="margin-bottom: 10px;">
		<div class="col-md-6 mbm" style="width: 700px; float:left; margin-right:-20px; display:inline;">
			<div class="input-group">
				<span class="input-group-btn">
					<button type="button" class="btn btn-default btn-outlined">源码备注<span class='require'>*</span></button>
				</span><input id="glueRemark" type="text" class="form-control" />
				 <div class="input-group-btn">
					<button type="button" data-toggle="dropdown"
						class="btn btn-blue dropdown-toggle">
						版本回溯 <i class="fa fa-angle-down"></i>
					</button>
					<ul id="version_back" role="menu" class="dropdown-menu pull-right">
					</ul>
				</div>
			</div>
		</div>
	</div>
	<div class="row" style="margin-bottom: 10px;">
		<div class="col-lg-12"
			style="width: 800px; float:left; margin-right:-20px; display:inline;">
			<div class="content-wrapper" id="ideWindow"></div>
		</div>
	</div>
	<input type="hidden" id="id" name="id" />

</div>
<?} ?>
<script src="static/codemirror/lib/codemirror.js"></script>
<script>
	var codeEditor;
	var index1 = window.parent.getlay();
	$("#id").val(index1);
	$(function() {
		init();
		//版本回溯
		
	});

	function glueSourceShow() {
		codeEditor = CodeMirror(document.getElementById("ideWindow"), {
			mode : "text/x-java",
			lineNumbers : true,
			matchBrackets : true,
			value : $("#version_now").val()
		});
	}
	 
	function source_version(obj){
		var temp = $( "#version_" + obj).val();
		codeEditor.setValue(temp);
	}
	function init() {
		$.getJSON("./xxljob_code_init.do", {
			id : index1
		//向服务端传的参数，此处只是演示
		}, function(res) {
			//此处仅仅是为了演示变化的内容
			var result = res.result;
			if (result == "ok") {
				var html="";
				var jobInfo = res.jobInfo;
				var jobLogGlues = res.jobLogGlues;
				html+='<li><a href="javascript:;" class="source_version" version="version_now" onclick="source_version(\'now\');">'+jobInfo[0].glueRemark+'</a></li>';
				html+='<li class="divider"></li>';
				html+='<textarea id="version_now" style="display:none;" >'+jobInfo[0].glueSource+'</textarea>';
				var jobLogGluesObj = eval(jobLogGlues);
				for(var i= 0; i< jobLogGluesObj.length;i++){
					html+='<li><a href="javascript:;" class="source_version" version="version_'+jobLogGluesObj[i].id+'" onclick="source_version('+jobLogGluesObj[i].id+');">'+jobLogGluesObj[i].glueRemark+'</a></li>';
					html+='<textarea id="version_'+jobLogGluesObj[i].id+'" style="display:none;" >'+jobLogGluesObj[i].glueSource+'</textarea>';
				}
				$("#version_back").append(html)
				glueSourceShow();
			} else {
				layer.msg("任务不存在！", {
					icon : 2
				});
			}
		});
	}
	//保存
	function Save(){
		var glueSource = codeEditor.getValue();
		var glueRemark = $("#glueRemark").val();
		$.ajax({
			type : "post",
			url : "./xxljob_code_save.do",
			data : {
				"id":$("#id").val(),
				"glueSource":glueSource,
				"glueRemark":glueRemark
			},
			dataType : "json",
			success : function(data) {
				if(data.result =="ok"){
					 var index = parent.layer.getFrameIndex(window.name); 
			         window.parent.get();
			         parent.layer.msg("保存成功!", {icon: 6});
			         parent.layer.close(index); 
				}else{
					layer.msg(data.result, {icon: 5});
				}
			},
			error : function(data) {
				layer.msg("请求失败！", {icon: 2});
			}
		});
	}
</script>


